import BaseConfig, { isDev } from './base.config'
import webpack, { Configuration } from 'webpack'
import path from 'path';
import nodeExternals from 'webpack-node-externals'
import { merge } from 'webpack-merge'

const config: Configuration = {
    target: 'node',
    devtool: isDev ? 'inline-source-map' : 'source-map',
    entry: './src/server',
    output: {
        filename: 'index.js',
        chunkFilename: '[name].js',
        path: path.resolve(process.cwd(), 'public/server'),
        libraryTarget: 'commonjs2',
    },
    node: {
        __dirname: true,
        __filename: true,
    },
    externals: [
        '@loadable/component',
        nodeExternals({
            // load non-javascript files with extensions, leave *.js files to be processed
            allowlist: [/\.(?!(?:jsx?|json)$).{1,5}$/i],

        }),
    ] as Configuration['externals'],
    plugins: [
        new webpack.BannerPlugin({
            banner: 'require("source-map-support").install();',  // last update
            raw: true,
        }),
    ],
}

export default merge(BaseConfig(false), config)